﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Weazel.Badger;

namespace BadgerTest.IpChecksum
{
	/// <summary>
	/// Summary description for RamblockTest
	/// </summary>
	[TestClass]
	public class IpChecksumTest
	{
		[TestMethod]
		public void TestIpChecksum()
		{
			try
			{
				string workingDir = "c:\\badger_test_temp\\";
				string description = BadgerTestUtillities.GetResourceFile("IpChecksum.ipchecksum.fdl");

				Weazel.Gezel.Model.Model model =
					BadgerTestUtillities.ParseAndVerify(description, 0);

				if (Directory.Exists(workingDir))
					Directory.Delete(workingDir, true);

				Directory.CreateDirectory(workingDir);

				Weazel.Badger.Configuration cfg = new Configuration();
				cfg.OutputFolder = "c:\\badger_test_temp\\";
				cfg.ConvertDisplayDirectives = true;
				cfg.CreateClockAndResetGenerationProcesses = true;		

				Weazel.Badger.ConversionContext conversion =
					new Weazel.Badger.ConversionContext(model, cfg);

				conversion.Convert();

				Assert.IsTrue(File.Exists(workingDir + "\\" + "S.vhd"));				
				Assert.IsTrue(File.Exists(workingDir + "\\" + "std_logic_arithext.vhd"));
				Assert.IsTrue(File.Exists(workingDir + "\\" + "weazel_text_io.vhd"));

				// create "work" library using vlib
				BadgerTestUtillities.RunVLib(workingDir, "work");


				// compile vhdl
				BadgerTestUtillities.RunVCom(workingDir, "std_logic_arithext.vhd");
				BadgerTestUtillities.RunVCom(workingDir, "weazel_text_io.vhd");
				BadgerTestUtillities.RunVCom(workingDir, "*.vhd");
				BadgerTestUtillities.RunVCom(workingDir, "*.vhd");
				BadgerTestUtillities.RunVCom(workingDir, "*.vhd");

				// simulate
				BadgerTestUtillities.RunVSim(workingDir, "work.s", "run 50000ns");

				/*
				// check that the output files has been written
				Assert.IsTrue(File.Exists(workingDir + "\\" + "monitor_display.txt"));
				Assert.IsTrue(File.Exists(workingDir + "\\" + "stimuli_display.txt"));

				// finally, compare output with reference
				string reference1 = BadgerTestUtillities.GetResourceFile("FullAdder.monitor_display.txt");
				Assert.AreEqual(reference1, BadgerTestUtillities.ReadFile(workingDir + "\\" + "monitor_display.txt"));

				string reference2 = BadgerTestUtillities.GetResourceFile("FullAdder.stimuli_display.txt");
				Assert.AreEqual(reference2, BadgerTestUtillities.ReadFile(workingDir + "\\" + "stimuli_display.txt"));
				 * */
			}
			catch (Exception)
			{
				Assert.Fail();
			}
		}
	}
}
